#include "PuzzleGameScoreNode.h" 
#include "cocos2d.h"
#include "editor-support\cocostudio\CocoStudio.h"
#include "cocos\ui\CocosGUI.h"
#include "..\cocos2d\extensions\cocos-ext.h"
#include "PuzzleGuess.h"  
#include "uiExt\RadiusNode.h"
  
NS_GAME_BEGIN

PuzzleGameScoreNode::PuzzleGameScoreNode()
:/*scoreBackcolorNode(nullptr)
,*/scoreTitleNode(nullptr)
,scoreValueNode(nullptr)
,scoreValue(0) 
{
	this->setRadiusStencilFillColor(cocos2d::Color4F(cocos2d::Color4B(181,170,156,200)));
	this->radiusA = 6;
	this->radiusB = 8;
}

PuzzleGameScoreNode::~PuzzleGameScoreNode()
{}

void PuzzleGameScoreNode::setContentSize(const cocos2d::Size& contentSize)
{
	RadiusNode::setContentSize(contentSize); 

	if(this->scoreTitleNode)
	{ 
		this->scoreTitleNode->setFontSize(this->getContentSize().height * 0.4 - 4); 
		this->scoreTitleNode->setPosition(cocos2d::Point(this->getContentSize().width*0.5, this->getContentSize().height*1 - this->scoreTitleNode->getFontSize() * 0.6));
		
		this->scoreValueNode->setFontSize(this->getContentSize().height * 0.6 - 4);
		this->scoreValueNode->setPosition(cocos2d::Point(this->getContentSize().width*0.5, this->getContentSize().height*0 +  this->scoreValueNode->getFontSize() * 0.6 ));
	}
}

bool PuzzleGameScoreNode::init()
{
	if(!RadiusNode::init())
	{
		return false;
	}

	/*this->scoreBackcolorNode = cocos2d::LayerColor::create(cocos2d::Color4B(181,170,156,200));
	this->setPosition(cocos2d::Point::ZERO);
	this->addChild(this->scoreBackcolorNode);*/

	this->scoreTitleNode = cocos2d::LabelTTF::create(); 
	this->scoreTitleNode->setColor(cocos2d::Color3B(239,227,214));
	this->scoreTitleNode->setFontSize(this->getContentSize().height * 0.4 - 4); 
	this->scoreTitleNode->setPosition(cocos2d::Point(this->getContentSize().width*0.5, this->getContentSize().height*1 - this->scoreTitleNode->getFontSize() * 0.6));
	this->scoreTitleNode->setString("Score"); 
	this->addChild(this->scoreTitleNode);

	this->scoreValueNode = cocos2d::LabelTTF::create();
	this->scoreValueNode->setColor(cocos2d::Color3B(255,255,255)); 
	this->scoreValueNode->setFontSize(this->getContentSize().height * 0.6 - 4);
	this->scoreValueNode->setPosition(cocos2d::Point(this->getContentSize().width*0.5, this->getContentSize().height*0 +  this->scoreValueNode->getFontSize() * 0.6 ));
	this->scoreValueNode->setString(cocos2d::StringUtils::format("%.1f",this->scoreValue));
	this->addChild(this->scoreValueNode);  

	return true;
}

void PuzzleGameScoreNode::setScoreTitle(const std::string& _scoreTitle)
{
	this->scoreTitleNode->setString(_scoreTitle);
}

void PuzzleGameScoreNode::setScoreValue(float _scoreValue)
{
	this->scoreValue = _scoreValue;
	this->scoreValueNode->setString(cocos2d::StringUtils::format("%.1f",this->scoreValue));
}

void PuzzleGameScoreNode::beginGameScore()
{
	this->schedule(schedule_selector(PuzzleGameScoreNode::gameScoreSchedule), 0.1f);
}

void PuzzleGameScoreNode::endGameScore()
{
	this->unschedule(schedule_selector(PuzzleGameScoreNode::gameScoreSchedule));
} 

void PuzzleGameScoreNode::gameScoreSchedule(float fDelta)
{
	this->setScoreValue(this->scoreValue + fDelta);
}
NS_GAME_END
